#!/bin/bash
sandboxdir=$(dirname $0)
. $sandboxdir/sb_vars.sh
. $sandboxdir/sb_common.sh

pre_installation fileapplier

SERVICE=$1
[ -z "$SERVICE" ] && SERVICE=mysql2fileapplier

export HOW_MANY_NODES=$2
[ -z "$HOW_MANY_NODES" ] && export HOW_MANY_NODES=3

if [ $HOW_MANY_NODES -lt 3  -o $HOW_MANY_NODES -gt 3 ]
then
    echo "3 nodes are required (found $HOW_MANY_NODES)"
    exit 1
fi

export BINLOG_FORMAT=row
$sandboxdir/sb_make_sandboxes
check_exit_code

set_fileapplier_options

if [ -n "$USE_INI" ]
then
    install_with_ini_files
else
    # Install master
    configure_defaults 1
    configure_master $SERVICE $THL_PORT_NODE1
    tpm_install

    configure_defaults 2
    configure_slave $SERVICE $THL_PORT_NODE2 --master-thl-port=$THL_PORT_NODE1
    tpm_install 

    configure_fileapplier_slave $SERVICE $THL_PORT_NODE3 $THL_PORT_NODE1 3
    tpm_install 
fi 

post_installation fileapplier

